﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TP</title>
    @*<script src="~/Scripts/jquery.tmpl/jquery.tmpl.js"></script>*@
    <script src="~/Scripts/jquery-3.3.1.js"></script>
    <script src="~/Scripts/laytpl/laytpl.js"></script>
</head>
<body>
    <div id="test">

    </div>

    <script>
    //${}, {{each}}, {{if}}, {{else}}, {{html}}
    $(function () {
        var data = {
            name: "李俊辉", nick: "bruke", KKKKK: { id: "1", name: "asdfasdf" }
        };

        //$("#testTemplate").tmpl(model).appendTo('#test');

        ////var reg = new RegExp("{{(\\w+)}}", "ig");
        ////var html = $("#testTemplate").html();

        //html = html.replace(reg, function (text, key) { return model[key]; });
        //$("#test").html(html);
        //var gettpl = $("#testTemplate").innerHTML;

        var gettpl = document.getElementById('testTemplate').innerHTML;
        laytpl(gettpl).render(data, function (html) {
        //得到的模板渲染到html
            document.getElementById('test').innerHTML = html;
        });
    });
    </script>

</body>
</html>


<script type="text/html" id="testTemplate">
    <div>
        <span>姓名:</span>{{d.name}}<br />
        <span>昵称:</span>{{d.nick}}<br />
    </div>
</script>